package dao.impl;

import dao.IItemDao;
import entities.Item;

public class ItemDao extends CommonDao<Item> implements IItemDao {


	public Item find(int id) {
		try {
			return em.find(Item.class, id);
		} catch (Exception e) {
			return null;
		}
	}

	@Override
	public String getWhereClause(Item obj) {
		StringBuilder clause = new StringBuilder();
		clause.append(" ");
		if (obj.getId() != null) {
			if (clause.length() > 1) {
				clause.append(" and");
				clause.append("id = ").append(" obj.getId").append(" ");
			}
		}
		if (obj.getVersion() != null) {
			if (clause.length() > 1) {
				clause.append(" and");
				clause.append("version = ").append(" obj.getVersion")
						.append(" ");
			}
		}
		if (obj.getTitle() != null) {
			if (clause.length() > 1) {
				clause.append(" and");
				clause.append("title = ").append(" obj.getTitle").append(" ");
			}
		}
			if (clause.length() > 1) {
				clause.append(" and");
				clause.append("checked = ").append(" obj.checked")
						.append(" ");
			}
		
		return clause.toString();
	}

}